package com.mofang.activity.interact;

import java.util.ArrayList;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.ListView;

import com.mofang.R;
import com.mofang.activity.BaseTitleViewActiviey;
import com.mofang.activity.MofangCommonUpdateView;
import com.mofang.activity.login.LoginActivity;
import com.mofang.adapters.InteractiveKnowledgeAdapter;
import com.mofang.controller.InteractiveController;
import com.pactera.framework.exception.IException;
import com.pactera.framework.model.MapEntity;

/**
 * @author gzh
 *	知识互动
 */
public class InteractiveKnowledgeActivity extends BaseTitleViewActiviey {

	private InteractiveKnowledgeAdapter adapter;
	private ListView knowledge_interactive_list;
	private KnowledgeInteractiveViewUpdate knowledgeInteractiveViewUpdate;
	private InteractiveController controller;
	private  ArrayList<MapEntity> dataList;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_knowledge_interactive);
		setNavigationTitle("知识互动");
		setNavigationLeftBtnImage(R.drawable.return_arrow);
		init();

	}

	private void init() {
		dataList=new ArrayList<MapEntity>();
		knowledgeInteractiveViewUpdate = new KnowledgeInteractiveViewUpdate(
				mContext);
		controller=new InteractiveController();
		controller.getKnowledge(knowledgeInteractiveViewUpdate, "00001");
		adapter = new InteractiveKnowledgeAdapter(getApplicationContext(),dataList);
		knowledge_interactive_list = (ListView) findViewById(R.id.knowledge_interactive_list);
		knowledge_interactive_list.setAdapter(adapter);
	}

	class KnowledgeInteractiveViewUpdate extends MofangCommonUpdateView<ArrayList<MapEntity>> {
		
		private ProgressDialog progressDialog;
		
		public KnowledgeInteractiveViewUpdate(Context context) {
			super(context);
		}
		@Override
		public void onPreExecute() {
			// TODO Auto-generated method stub
			progressDialog = ProgressDialog.show(mContext, null,
					"加载中...", true, false);
			super.onPreExecute();
		}

		@Override
		public void onPostExecute(ArrayList<MapEntity> arg0) {
			// TODO Auto-generated method stub
			dataList=arg0;
			adapter = new InteractiveKnowledgeAdapter(getApplicationContext(),dataList);
			progressDialog.dismiss();
		}

		@Override
		public void handleException(IException ex) {
			// TODO Auto-generated method stub
			viewHelper.showBTNDialog(ex.getMessage());
		}
	}
}
